package com.win.cn.core.pane;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Alert;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Alert.AlertType;

/**
 * 标题模板
 * 
 * @author wangzh
 * 2018年6月6日 上午11:10:57
 */
public class TopPane {
	
	/**
	 * 创建头
	 * @return
	 */
    public MenuBar  createTopMenu(){
    	
	    Menu fileMenu = new Menu("文件");
	    MenuItem newMenuItem = new MenuItem("新建");
	    MenuItem saveMenuItem = new MenuItem("保存");
	    MenuItem exitMenuItem = new MenuItem("退出");
	    exitMenuItem.setOnAction(actionEvent -> Platform.exit());

	    fileMenu.getItems().addAll(newMenuItem, saveMenuItem,new SeparatorMenuItem(), exitMenuItem);

	    Menu webMenu = new Menu("网页");
	    CheckMenuItem htmlMenuItem = new CheckMenuItem("HTML");
	    htmlMenuItem.setSelected(true);
	    webMenu.getItems().add(htmlMenuItem);

	    CheckMenuItem cssMenuItem = new CheckMenuItem("CSS");
	    cssMenuItem.setSelected(true);
	    webMenu.getItems().add(cssMenuItem);

	    Menu sqlMenu = new Menu("数据库");
	    ToggleGroup tGroup = new ToggleGroup();
	    RadioMenuItem mysqlItem = new RadioMenuItem("MySQL");
	    mysqlItem.setToggleGroup(tGroup);

	    RadioMenuItem oracleItem = new RadioMenuItem("Oracle");
	    oracleItem.setToggleGroup(tGroup);
	    oracleItem.setSelected(true);

	    sqlMenu.getItems().addAll(mysqlItem, oracleItem,
	        new SeparatorMenuItem());

	    Menu tutorialManeu = new Menu("界面");
	    tutorialManeu.getItems().addAll(
	        new CheckMenuItem("Java"),
	        new CheckMenuItem("JavaFX"),
	        new CheckMenuItem("Swing"));

	    sqlMenu.getItems().add(tutorialManeu);
	    
	    Menu aboutMenu = new Menu("关于");
	    aboutMenu.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
	    		
	            Alert alert = new Alert(AlertType.INFORMATION);
	            alert.setTitle("作者");
	            alert.setHeaderText(null);
	            alert.setContentText("王宗会个人工具");

	            alert.showAndWait();
            }});
	    
	    MenuItem authorMenuItem = new MenuItem("作者");

	    aboutMenu.getItems().addAll(authorMenuItem);
	    
	    MenuBar menuBar=new MenuBar();
	    menuBar.getMenus().addAll(fileMenu, webMenu, sqlMenu,aboutMenu);
	    return menuBar;
    }

}
